import { getItem, setItem } from '@/utils/storage'
import { setTheme } from '@/components/换肤/theme'
import { getType } from '@/utils/deepClone'
export default {
  namespaced: true,
  state: () => ({
    theme: getItem('Theme') || 'light',
    sidebarOpened: true
  }),
  mutations: {
    setTheme(state, payload) {
      if (payload) {
        setItem('Theme', payload)
        state.theme = payload
        setTheme(payload)
      }
    },
    changeSidebarOpened(state, payload) {
      if (getType(payload).toLocaleLowerCase() === 'boolean') {
        state.sidebarOpened = Boolean(payload)
      } else {
        state.sidebarOpened = !state.sidebarOpened
      }
    }
  },
  getters: {
    // 测试命名空间的getter如何再组件中获取并使用
    testAppGetters(state, getters, rootState) {
      console.log('app中的', getters)
      return state.theme + rootState.userinfo.name
    }
  }
}
